import 'package:flutter/material.dart';

class BoxMoveAnimation extends StatefulWidget {
  final Widget child;
  final int duraction;

  BoxMoveAnimation({
    Key key, 
    this.child,
    this.duraction = 600
  }) 
  : super(key: key);
  
  @override
  _BoxMoveAnimationState createState() => _BoxMoveAnimationState();
}

class _BoxMoveAnimationState extends State<BoxMoveAnimation> with TickerProviderStateMixin {
  AnimationController controller;
  Animation<Offset> animation;

  AnimationController _controller;
  Animation _animation;

  @override
  void initState() {
    super.initState();
    controller = AnimationController(duration: Duration(milliseconds: widget.duraction), vsync: this);
    animation = Tween(begin: Offset(0, 2), end: Offset(0, 0)).animate(controller);
    controller.forward();

    _controller = AnimationController(vsync: this,duration: Duration(milliseconds: widget.duraction));
    _animation = Tween(begin: 0.2, end: 1.0,).animate(_controller);
    _controller.forward();
  }

  @override
  Widget build(BuildContext context) {

    return FadeTransition(
      opacity: _animation,
      child: SlideTransition(
        position: animation,
        child: widget.child, //将要执行动画的子view
      )
    );
  }
}
